﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class admin_luru : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private static string strcon = "Integrated Security=SSPI;Data Source=(local);initial catalog=tsmanager";
    protected void Button1_Click(object sender, EventArgs e)
    {
        string bookid = TextBox1.Text.Trim();
        string bookname = TextBox2.Text.Trim();
        string booktype = TextBox3.Text.Trim();
        string bookzz = TextBox4.Text.Trim();
        string bookcbs = TextBox7.Text.Trim();
        string bookcbrq = TextBox6.Text.Trim();
        int bookkc = Convert.ToInt32(TextBox5.Text.Trim());
        int bookjc = 0;
        string strcom = "insert into BookInformation(BI_BID,BI_TITLE,BI_TYPE,BI_AUTHOR,BI_NOB,BI_PUBLISHER,BI_PYEAR) values('" + bookid + "','" + bookname + "','" + booktype + "','" + bookzz + "','" + bookkc + "','" + bookcbs + "','" + bookcbrq + "')";
        SqlConnection con = new SqlConnection(strcon);
        con.Open();
        SqlCommand com = new SqlCommand(strcom,con);
        try
        {
            com.ExecuteNonQuery();
            //selecttype(booktype);

            string str11 = "insert into BookManagement(RMF_WTIME,BI_BID,librarianID) values ('" + DateTime.Now.ToShortDateString().ToString() + "','" + bookid + "','" + Session["glyid"].ToString() + "')";
            SqlCommand SC1 = new SqlCommand(str11, con);
            SC1.ExecuteNonQuery();

            Response.Write("<script language=javascript>alert('录入成功')</script>");
            con.Close();
        }
        catch(Exception ex) {
            Response.Write("<script language=javascript>alert('录入失败')</script>");
            Response.Write(ex);
            con.Close();
        }

    }


    protected void selecttype(string booktype)
    {
        string strcom = "select * from zsgctable where select_type='" + booktype + "'";
        SqlConnection con = new SqlConnection(strcon);
        con.Open();
        SqlCommand com = new SqlCommand(strcom, con);
        try
        {
            SqlDataReader sdr =  com.ExecuteReader();
            if (sdr.Read())
            {
                Response.Write("<script language=javascript>alert('没有相同类别')</script>");
            }
            else {
                insertype(booktype);
            }
        }
        catch (Exception ex)
        {
            
        }
    }
        

    protected void insertype(string booktype) {
        string strcom = "insert into zsgctable(select_type) values('"+booktype+"')";
        SqlConnection con = new SqlConnection(strcon);
        con.Open();
        SqlCommand com = new SqlCommand(strcom, con);
        try
        {
            com.ExecuteNonQuery();
            Response.Write("<script language=javascript>alert('类型录入成功')</script>");
            con.Close();
        }
        catch (Exception ex)
        {
            Response.Write("<script language=javascript>alert('类型录入失败')</script>");
            Response.Write(ex);
            con.Close();
        }
    }
}